<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
</head>
<body>
<div class="layui-panel" style="padding: 8px;">
    <fieldset class="layui-elem-field  layui-border-blue">
        <legend>搜索区域</legend>
        <form class="layui-form layui-form-pane" style="margin: 20px;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="userId" autocomplete="off" placeholder="请输入用户id" />
                    </div>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="receiver" autocomplete="off" placeholder="请输入收货人姓名" />
                    </div>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchBtn">
                        <i class="layui-icon layui-icon-search"></i>
                        查找
                    </a>
                    <a class="layui-btn layui-btn-normal" lay-submit="" lay-filter="">
                        <i class="layui-icon layui-icon-down"></i>
                        导出
                    </a>
                </div>
            </div>
        </form>
    </fieldset>
    <div >
        <table id="addressTable" lay-filter="addressTable" class="layui-table layui-form" ></table>
    </div>
    <script id="tableBar" type="text/html">
        <a class="layui-btn layui-btn-normal layui-btn-md" lay-event="add">
            <i class="layui-icon layui-icon-add-1"></i>
            新增
        </a>
        <!--<a class="layui-btn layui-btn-danger layui-btn-md" lay-event="delete">
            <i class="layui-icon layui-icon-delete"></i>
            删除
        </a>-->
    </script>

    <script id="tool" type="text/html">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">详情</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>
</div>
<script>
    var $;


    layui.use(['table','form','jquery'],function(){
        var table = layui.table,form = layui.form;$=layui.jquery;


        //加载表格
        table.render({
            elem:'#addressTable',
            height:'full-160',
            toolbar:'#tableBar',
            url:"/address/ra/find",
            page: {
                theme:'#1e9fff'
            },
            cols:[
                [
                    {field:'id',title:'地址id',width:100,align:'center'},
                    {field:'userId',title:'用户id',width:100,align:'center'},
                    {field:'receiver',title:'收货人名称',width:200,align:'center'},
                    {field:'phone',title:'用户手机',width:200,align:'center'},
                    {field:'areaAddress',title:'区域地址',width:300,align:'center'},
                    {field:'address',title:'详细地址',align:'center'},
                    {field:'status',title:'默认',width:200,align:'center',
                        templet:function (res) {
                            if("1" == res.status){return "<span style='background-color: #e8f4ff;border-color:#d1e9ff;color: #1890ff;border-radius:5px;padding: 2px 5px;display:inline-block'>是</span>"}
                            else if("2" == res.status){return "<span style='background-color: #e8f4ff;border-color:#d1e9ff;color: #1890ff;border-radius:5px;padding: 2px 5px;display:inline-block'>否</span>"};}
                    },
                    {fixed:'right',title:'操作',width:200,align:'center',toolbar:'#tool'}
                ]
            ],

        })
        //监听搜索按钮
        form.on('submit(searchBtn)',function(data){
            var dataForm = data.field;

            table.reload('addressTable',{
                where:{
                    userId:dataForm.userId,
                    receiver:dataForm.receiver
                }

            })
            console.log(dataForm.userId);
            console.log(dataForm.receiver)
        })

        var active = {
            addOrUpdate:function (content){
                var b = false;
                top.layer.open({
                    type:2,
                    content:content,
                    area:['900px','800px'],
                    btn:['确定保存','取消关闭'],
                    btn1:function (i,o){
                        b = true;
                        o.find('iframe')[0].contentWindow.btnSubmit();
                    },
                    end:function (){
                        if (b) layui.table.reload('addressTable');
                    }
                })
            },
            deleteConfirm:function (id) {
                $.ajax({
                    type:'post',
                    url:'/address/ra/delete',
                    dataType: 'json',
                    data:{
                        id:id,
                    },
                    success:function (result) {
                        var tip = result.msg;
                        layer.msg(tip);
                        if(result.is){
                            layui.table.reload('addressTable');
                        }
                    }
                })
            }
        }

        table.on('tool(addressTable)',function (obj){
            var event = obj.event;
            if("edit" == event){
                active.addOrUpdate('/page/address/addressEdit/'+obj.data.id);
            }else if ("delete == event"){
                active.deleteConfirm(obj.data.id);
            }
        })
        table.on('toolbar(addressTable)',function (obj) {
            var event = obj.event;
            if("add" == event){
                active.addOrUpdate('/page/address/addressAdd');
            }
        })
    });

</script>
</body>
</html>